import 'package:flutter/material.dart';

import '../../foundation/decoration/public_box_shadow.dart';

/// FileName clip_radius_container
///
/// @Author lax
/// @Date 2023/6/28
///
/// @Description

class ClipRadiusContainer extends StatelessWidget {
  final double? radius;

  /// 设置后radius失效
  final BorderRadiusGeometry? borderRadius;

  final double? width;

  final double? height;

  final Color? color;

  final Color? shadowColor;

  final EdgeInsets? padding;

  final EdgeInsets? margin;

  final Alignment? alignment;

  final Decoration? decoration;

  final Widget? child;

  const ClipRadiusContainer({
    super.key,
    this.radius = 5,
    this.borderRadius,
    this.width,
    this.height,
    this.color = Colors.white,
    this.shadowColor,
    this.padding,
    this.margin,
    this.alignment,
    this.decoration,
    this.child,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: margin ?? EdgeInsets.zero,
      child: radius == null
          ? body()
          : ClipRRect(
              borderRadius: borderRadius ?? BorderRadius.circular(radius ?? 0),
              child: body(),
            ),
    );
  }

  Widget body() {
    return Container(
      width: width,
      height: height,
      padding: padding,
      alignment: alignment,
      decoration: decoration ??
          BoxDecoration(
            color: color,
            boxShadow: shadowColor == null
                ? null
                : [PublicBoxShadow(color: shadowColor)],
            borderRadius: BorderRadius.circular(radius ?? 0),
          ),
      child: child,
    );
  }
}
